﻿using Abp.Domain.Repositories;
using AppFramework.DinosaursParkMes.Product;
using AppFramework.DinosaursParkMes.ProductClass.DTO;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFramework.DinosaursParkMes.ProductClass
{
    /// <summary>
    /// 产品分类管理
    /// </summary>
    public class ProductClassificationAppService : AppFrameworkAppServiceBase, IProductClassificationAppService
    {
        private readonly IRepository<ProductClassification> repository;

        public ProductClassificationAppService(IRepository<ProductClassification> repository)
        {
            this.repository = repository;
        }
        [HttpGet,Route("ShowProductClass")]
        public List<ProductClassResponseDTO> ShowProductClass(int pid)
        {
            var list = repository.GetAllList();
            return Recursion(list.ToList(),pid);
        }
        
        public List<ProductClassResponseDTO> Recursion(List<ProductClassification> list,int pid)
        {
             List<ProductClassResponseDTO> dto=new List<ProductClassResponseDTO>();
            var list1 = list.Where(m => m.Fatherid == pid);
            foreach (var item in list1)
            {
                dto.Add(new ProductClassResponseDTO() { value = item.Id, label = item.Classname, children = Recursion(list, item.Id) });
            }
            return dto.Count()>0?dto:null;
        }

    }
}
